<!DOCTYPE html>
<html lang="zh-cn" >
	<head>
		<title>用户登录</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link href="${rc.contextPath}/css/bootstrap.min.css" rel="stylesheet">
		<link href="${rc.contextPath}/css/bootstrap-responsive.min.css" rel="stylesheet">
		
		<script src="${rc.contextPath}/js/jquery-1.7.2.min.js"></script>
		<script src="${rc.contextPath}/js/bootstrap.min.js"></script>
		
		<style type="text/css">
			.colM{width:220px; margin:70px auto;margin-top:226px;}
			.submit-row{margin-left:166px;}
		</style>
	</head>


	<body class="login">
		<!-- Container -->
		<div class="container-fluid">
		    <!-- Header -->
		    <div class="navbar navbar-inverse navbar-fixed-top">
		      <div class="navbar-inner">
		        <div class="container-fluid">
		          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
		            <span class="icon-bar"></span>
		            <span class="icon-bar"></span>
		            <span class="icon-bar"></span>
		          </a>
				  <a class="brand" href="/admin/">管理后台</a>
		          <div class="nav-collapse collapse">
		            <ul class="nav pull-right">
		                <li class="divider-vertical"></li>
		            </ul>
		          </div><!--/.nav-collapse -->
		        </div>
		      </div>
		    </div>
		    <!-- END Header -->
		    <div class="row-fluid">
		        <div class="span12">
		        </div>
		    </div>
		    <!-- Content -->
		    <div id="content" class="colM">
				<div id="content-main">
				<form action="${rc.contextPath}/login/sign" method="post" id="login-form">
                    <#if message??>
                        <div class="alert alert-error">
                            <span>${message}</span>
                        </div>
                    </#if>
				  <input id="uri" type="hidden" name="uri" value="${uri!}"/>
				  <div class="form-row">
				    <label for="phone" class="required">手机号</label>
				    <input id="phone" type="text" name="phone" maxlength="11" />
				  </div>
				  <div class="form-row">
				    <label for="code" class="required">密码：</label> 
				    <input id="code" type="text" name="code" maxlength="6" style="width:105px;"/><a class="btn btn-sm" href="javascript:getCode()" style="margin-top: -10px;margin-left: 15px;">获取验证码</a>
				  </div>
				  <div class="submit-row">
				    <label><a class="btn btn-info btn-sm" href="javascript:loginFormSubmit()">登录</a></label>
				  </div>
				</form> 
				</div>
		    </div>
		    <!-- END Content -->
		    <footer id="footer"></footer>
		</div>
		<!-- END Container -->
	</body>
<script>
	var getCodeFlag = true;
	function getCode(){
		if (getCodeFlag){
			getCodeFlag = false;
			var phone = $("#phone").val();
			if (!(/^1+[0-9]*\d{10}$/.test(phone))){
				alert("请输入正确的手机号码");
				getCodeFlag = true;
				return;
			}
			$.ajax({
				url : "${rc.contextPath}/login/getCode",
		    	dataType : "json",
		    	data :  {"phone":phone},
		    	type:'post',
		    	success:function(json){
		    		if(json.code == 0){
		    			alert(json.message);
		    		} else {
		    			alert(json.message+":"+json.data);
		    		}
	    			getCodeFlag = true;
		    	},
		    	error:function(){
		    		getCodeFlag = true;
		    	}
			});
		}
	}
	
	var loginFormSubmitFlag = true;
	function loginFormSubmit(){
		if (loginFormSubmitFlag){
			loginFormSubmitFlag = false;
			var phone = $("#phone").val();
			if (!(/^1+[0-9]*\d{10}$/.test(phone))){
				alert("请输入正确的手机号码");
				loginFormSubmitFlag = true;
				return;
			}
			var code = $("#code").val();
			if (!(/^[0-9]*\d{6}$/.test(code))){
				alert("请输入正确的验证码");
				loginFormSubmitFlag = true;
				return;
			}
			$.ajax({
				url : "${rc.contextPath}/login/sign",
		    	dataType : "json",
		    	data :  $("#login-form").serialize(),
		    	type:'post',
		    	success:function(json){
		    		if(json.code == 0){
						location.href = json.data;		    		
		    		} else {
		    			alert(json.message+":"+json.data);
		    		}
	    			loginFormSubmitFlag = true;
		    	},
		    	error:function(){
		    		loginFormSubmitFlag = true;
		    	}
			});
		}
	}
</script>
</html>
